<?php

class ChatListing extends AbstractBox {
	protected $template = 'message/chat_listing.tpl';
	
	protected $onPage = 10;
	
	protected function setup() {
		$loggedUser = LoggedUser::whoIsLogged();
		if (!$loggedUser) {
			Utils::redirect('uvod.html');
		}
		
		$messageRepository = new MessageRepository();
		$messageRepository->setLimit($this->onPage);
		$page = 1;
		if (Utils::get('page')) {
			$page = intval(Utils::get('page'));
		}
		$messageRepository->setPage($page);
		$messageList = $messageRepository->getChatListForUser($loggedUser);
		
		$count = $messageRepository->getCountAllChatListForUser($loggedUser);
		$pages = array();
		$pageCount = ceil($count / $this->onPage);
		if ($pageCount > 1) {
			for ($i = 1; $i <= $pageCount; $i++) {
				$pages[] = $i;
			}
		}
		MySmarty::assign('pages', $pages);
		MySmarty::assign('messageList', $messageList);
		MySmarty::assign('actualState', Utils::get());
	}
}

?>